package com.etc.controller;

import com.etc.dto.Result;
import com.etc.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @PostMapping("/login")
    public @ResponseBody
    Result adminLogin(@RequestParam String username, @RequestParam String password, HttpServletRequest request) {
        boolean flag = false;
        Result result = new Result();
        Admin admin = new Admin();
        admin.setUsername("admin");
        admin.setPassword("123");
        if ("admin".equals(username) && "123".equals(password)) {
            request.getSession().setAttribute("admin", admin);
            flag = true;
            return result.ok(flag);
        }
        return result.ok(flag);
    }

}
